package com.snack.system.controller;

import com.snack.common.core.web.controller.BaseController;
import com.snack.common.core.web.domain.AjaxResult;
import com.snack.common.core.web.page.TableDataInfo;
import com.snack.common.log.annotation.Log;
import com.snack.common.log.enums.BusinessType;
import com.snack.common.security.annotation.RequiresPermissions;
import com.snack.system.domain.TsOrder;
import com.snack.system.service.ITsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单Controller
 * 
 * @author snack
 * @date 2022-09-18
 */
@RestController
@RequestMapping("/order")
public class TsOrderController extends BaseController
{
    @Autowired
    private ITsOrderService orderService;

    /**
     * 查询订单列表
     */
    @RequiresPermissions("system:order:list")
    @GetMapping("/list")
    public TableDataInfo list(TsOrder order)
    {
        startPage();
        List<TsOrder> list = orderService.selectList(order);
        return getDataTable(list);
    }

    /**
     * 获取订单详细信息
     */
    @RequiresPermissions("system:order:query")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return AjaxResult.success(orderService.selectById(orderId));
    }

    /**
     * 新增订单
     */
    @RequiresPermissions("system:order:add")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TsOrder order)
    {
        return toAjax(orderService.insert(order));
    }

    /**
     * 修改订单
     */
    @RequiresPermissions("system:order:edit")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TsOrder order)
    {
        return toAjax(orderService.update(order));
    }

    /**
     * 删除订单
     */
    @RequiresPermissions("system:order:remove")
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(orderService.deleteByIds(orderIds));
    }
}
